package com.currentcms.client.event;

import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.user.client.ui.Widget;

public class SelectEvent<T> extends GwtEvent<SelectHandler<T>>
{
	private static Type<SelectHandler<?>> TYPE;

	public static Type<SelectHandler<?>> getType()
	{
		if (TYPE == null)
		{
			TYPE = new Type<SelectHandler<?>>();
		}
		return TYPE;
	}

	private Widget _source;
	private T _data;

	public SelectEvent(Widget source, T data)
	{
		_source = source;
		_data = data;
	}
	
	public Widget getSource()
	{
		return _source;
	}
	
	public T getData()
	{
		return _data;
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public final Type<SelectHandler<T>> getAssociatedType()
	{
		return (Type) TYPE;
	}

	@Override
	public String toDebugString()
	{
		assertLive();
		return super.toDebugString();
	}

	@Override
	protected void dispatch(SelectHandler<T> handler)
	{
		handler.onSelectEvent(this);
	}
}
